package com.boot.security.server.dao.mffl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.boot.security.server.model.mffl.MfflType;

@Mapper
public interface MfflTypeDao {


    //查询该类型是否存在，并且符合类型
    @Select("select * from mffl_type t where t.id = #{id} AND t.type = #{typeid}")
    MfflType getByTypeId(@Param("id") Integer id, @Param("typeid") Integer typeid);


    @Select("select * from mffl_type t where t.id = #{id}")
    MfflType getById(Long id);

    @Delete("delete from mffl_type where id = #{id}")
    int delete(Long id);

    int update(MfflType mfflType);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_type(name, content, `order`, createTime, updateTime, type) values(#{name}, #{content}, #{order}, #{createTime}, #{updateTime}, #{type})")
    int save(MfflType mfflType);
    //后台-资讯分类管理count
    int count(@Param("params") Map<String, Object> params);
    //后台-资讯分类管理list
    List<MfflType> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);


    //后台-律师分类管理count
    int lawyerCount(@Param("params") Map<String, Object> params);
    //后台-律师分类管理list
    List<MfflType> lawyerList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);


    @Select("SELECT * FROM `mffl_type` where type = #{serviceid} ORDER BY `order`,createTime ASC")
    List<MfflType> getConsultationType(Integer serviceid);

    //获取资讯分类
    @Select(" select mt.* from mffl_service ms ,mffl_type mt where mt.`type` =ms.id and ms.name = '资讯' order by mt.`order` ")
    List<MfflType> getInformationType();

    //获取律师分类
    @Select(" select mt.* from mffl_service ms ,mffl_type mt where mt.`type` =ms.id and ms.name = '免费咨询' order by mt.`order` ")
    List<MfflType> getLawyerType();

    @Select("select name from mffl_type where id in (${field})")
    List<String> getLawyerTypeListById(@Param("field") String field);


    //获取服务类型
    @Select("select * from mffl_type t where t.type = #{typeid}")
    List<MfflType> getServiceTypeId(@Param("typeid") Integer typeid);
    //获取资讯绑定的serviceId
    @Select("select id from mffl_service where name= #{name}")
    Integer getInformationIdByName(@Param("name") String name);

}
